<!--
 * @Description: 
 * @Author: mmzhang
 * @Date: 2022-10-31 10:17:18
 * @LastEditTime: 2022-12-19 13:32:02
-->
<template>
  <div class="sales">
    <p class="title">销售统计</p>
    <div class="flex flex-horizontal-between">
      <ul class="sales-content" v-for="(item,index) in saleData" :key="index">
        <li v-for="(itemCur,indexCur) in item" :key="indexCur"
          :class="['flex', 'flex-horizontal-between' ,'flex-vertical-center',{'hand':salesInfo[itemCur.buildKey]!==0||salesInfo[itemCur.moneyKey]!==0}]"
          @click="linkPageFun(itemCur,index==2)">
          <div class="flex">
            <p class="text-center">{{itemCur.label}}：</p>
            <p v-if="itemCur.buildKey!='buybackQuantity' && itemCur.buildKey!='cumulateBuybackQuantity'"
              class="text-center">
              {{salesInfo[itemCur.buildKey]}}套<span
                class="money">({{salesInfo[itemCur.moneyKey]}}元)</span>
            </p>
            <p v-else class="text-center">{{salesInfo[itemCur.moneyKey]}}元</p>
          </div>
          <Icon type="ios-arrow-forward" :size="16"
            v-if="salesInfo[itemCur.buildKey]!==0||salesInfo[itemCur.moneyKey]!==0" />
        </li>
      </ul>
    </div>
  </div>
</template>
<script>
  import dt from '@dt/dt'
  import homeMgr from '@/biz/buildingHome/home'
  export default {
    data() {
      return {
        //1: 认购 2: 退购 3: 退签 5: 签约 6: 全款
        saleData: [
          [{
            label: '认购',
            type: 'subscriptionOrder',
            buildKey: 'subscribeQuantity',
            moneyKey: 'subscribeAmount',
            containDate: ['1'],
            queryType:1,
            status: ['4', '6', '7', '8'] //认购未签约、认购已退购、认购已签约、认购已退签
          }, {
            label: '退购',
            type: 'subscriptionOrder',
            buildKey: 'retreatSubscribeQuantity',
            moneyKey: 'retreatSubscribeAmount',
            containDate: ['2'],
            queryType:2,
            status: ['6'] //认购已退购
          }, {
            label: '足未签',
            type: 'subscriptionOrder',
            buildKey: 'notContractQuantity',
            moneyKey: 'notContractAmount',
            containDate: ['1'],
            queryType:6,
            status: ['4'] //认购未签约
          }, {
            label: '净认购',
            type: 'subscriptionOrder',
            buildKey: 'subscribeNetWorthQuantity',
            moneyKey: 'subscribeNetWorthAmount',
            containDate: ['1', '2'],
            queryType:8,
            status: ['4', '6', '7', '8'] //认购未签约、认购已退购、认购已签约、认购已退签
          }, {
            label: '实际净认购',
            type: 'subscriptionOrder',
            buildKey: 'actualSubscribeNetWorthQuantity',
            moneyKey: 'actualSubscribeNetWorthAmount',
            containDate: ['1', '2', '3'],
            queryType:9,
            status: ['4', '6', '7', '8'] //认购未签约、认购已退购、认购已签约、认购已退签
          }],
          [{
            label: '签约',
            type: 'contractOrder',
            buildKey: 'contractQuantity',
            moneyKey: 'contractAmount',
            containDate: ['5'],
            queryType:3,
            status: ['10104', '10109', '10106'] //签约回款中、签约已全款、签约已退签
          }, {
            label: '退签',
            type: 'contractOrder',
            buildKey: 'retreatContractQuantity',
            moneyKey: 'retreatContractAmount',
            containDate: ['3'],
            queryType:4,
            status: ['10106'] //签约已退签
          }, {
            label: '净签约',
            type: 'contractOrder',
            buildKey: 'contractNetWorthQuantity',
            moneyKey: 'contractNetWorthAmount',
            containDate: ['5', '3'],
            queryType:10,
            status: ['10104', '10109', '10106'] //签约回款中、签约已全款、签约已退签
          }, {
            label: '已全款',
            type: 'contractOrder',
            buildKey: 'fullPaymentQuantity',
            moneyKey: 'fullPaymentAmount',
            containDate: ['6'],
            queryType:5,
            status: ['10109'] //签约已全款
          }, {
            label: '回款金额',
            type: 'paymentArrival',
            buildKey: 'buybackQuantity',
            moneyKey: 'buybackAmount',
            queryType:7,
            status: ['2'], //已入账
          }],
          [{
            label: '累计足未签',
            type: 'subscriptionOrder',
            buildKey: 'cumulateNotContractQuantity',
            moneyKey: 'cumulateNotContractAmount',
            containDate: ['1', '2', '3'],
            queryType:11,
            status: ['4'] //认购未签约
          }, {
            label: '累计净签约',
            type: 'contractOrder',
            buildKey: 'cumulateContractNetWorthQuantity',
            moneyKey: 'cumulateContractNetWorthAmount',
            containDate: ['5', '3'],
            status: ['10104', '10109', '10106'] //签约回款中、签约已全款、签约已退签
          }, {
            label: '累计未全款',
            type: 'contractOrder',
            buildKey: 'cumulateNotFullPaymentQuantity',
            moneyKey: 'cumulateNotFullPaymentAmount',
            containDate: ['5', '3'],
            queryType:12,
            status: ['10104'] //签约回款中
          }, {
            label: '累计已全款',
            type: 'contractOrder',
            buildKey: 'cumulateFullPaymentQuantity',
            moneyKey: 'cumulateFullPaymentAmount',
            containDate: ['5', '3'],
            status: ['10109'] //签约已全款
          }, {
            label: '累计回款金额',
            type: 'paymentArrival',
            buildKey: 'cumulateBuybackQuantity',
            moneyKey: 'cumulateBuybackAmount',
            status: ['2'], //已入账
          }]
        ],
        salesInfo: {
          actualSubscribeNetWorthAmount: 0,
          actualSubscribeNetWorthOrderIds: [],
          actualSubscribeNetWorthQuantity: 0,
          buybackAmount: 0,
          buybackQuantity: 0,
          buybackContractIds: [],
          contractAmount: 0,
          contractNetWorthAmount: 0,
          contractNetWorthOrderIds: [],
          contractNetWorthQuantity: 0,
          contractOrderIds: [],
          contractQuantity: 0,
          cumulateBuybackAmount: 0,
          cumulateBuybackQuantity: 0,
          cumulateBuybackContractIds: [],
          cumulateContractNetWorthAmount: 0,
          cumulateContractNetWorthOrderIds: [],
          cumulateContractNetWorthQuantity: 0,
          cumulateFullPaymentAmount: 0,
          cumulateFullPaymentOrderIds: [],
          cumulateFullPaymentQuantity: 0,
          cumulateNotContractAmount: 0,
          cumulateNotContractOrderIds: [],
          cumulateNotContractQuantity: 0,
          cumulateNotFullPaymentAmount: 0,
          cumulateNotFullPaymentOrderIds: [],
          cumulateNotFullPaymentQuantity: 0,
          fullPaymentAmount: 0,
          fullPaymentOrderIds: [],
          fullPaymentQuantity: 0,
          notContractAmount: 0,
          notContractOrderIds: [],
          notContractQuantity: 0,
          retreatContractAmount: 0,
          retreatContractOrderIds: [],
          retreatContractQuantity: 0,
          retreatSubscribeAmount: 0,
          retreatSubscribeOrderIds: [],
          retreatSubscribeQuantity: 0,
          subscribeAmount: 0,
          subscribeNetWorthAmount: 0,
          subscribeNetWorthOrderIds: [],
          subscribeNetWorthQuantity: 0,
          subscribeOrderIds: [],
          subscribeQuantity: 0
        },
        checkIndex: null,
        checkTime: [],
        checkParams:{}
      }
    },
    created(){
      if(this.$tool.getStorage('isbuildFlag') == 'nobuildpage'){
        this.saleData[2] = [{
          label: '累计足未签',
          type: 'subscriptionOrder',
          buildKey: 'cumulateNotContractQuantity',
          moneyKey: 'cumulateNotContractAmount',
          containDate: ['1', '2', '3'],
          queryType:11,
          status: ['4'] //认购未签约
        },{
          label: '累计未全款',
          type: 'contractOrder',
          buildKey: 'cumulateNotFullPaymentQuantity',
          moneyKey: 'cumulateNotFullPaymentAmount',
          containDate: ['5', '3'],
          queryType:12,
          status: ['10104'] //签约回款中
        }]
      }
    },
    mounted(){
    },
    methods: {
      getSalesData(checkParams,res={}) {
        this.checkParams = checkParams
        this.checkIndex = checkParams.checkIndex
        this.checkTime = [checkParams.startTime + ' 00:00:00', checkParams.endTime + ' 23:59:59']

        if(Object.keys(res).length){
          this.salesInfo = res.sales
          this.salesInfo.buybackQuantity = 0
          this.salesInfo.cumulateBuybackQuantity = 0
        }else{
          let params = {
            orgId: this.$dt.buildInfo().housesId,
            level: 4,
            startTime: checkParams.startTime,
            endTime: checkParams.endTime
          }
          homeMgr
            .getHousesDayReportList(params)
            .then((res) => {
              this.salesInfo = { ...res }
              this.salesInfo.buybackQuantity = 0
              this.salesInfo.cumulateBuybackQuantity = 0
            })
            .catch((err) => {
              this.salesInfo = {
                actualSubscribeNetWorthAmount: 0,
                actualSubscribeNetWorthOrderIds: [],
                actualSubscribeNetWorthQuantity: 0,
                buybackAmount: 0,
                buybackQuantity: 0,
                buybackContractIds: [],
                contractAmount: 0,
                contractNetWorthAmount: 0,
                contractNetWorthOrderIds: [],
                contractNetWorthQuantity: 0,
                contractOrderIds: [],
                contractQuantity: 0,
                cumulateBuybackAmount: 0,
                cumulateBuybackQuantity: 0,
                cumulateBuybackContractIds: [],
                cumulateContractNetWorthAmount: 0,
                cumulateContractNetWorthOrderIds: [],
                cumulateContractNetWorthQuantity: 0,
                cumulateFullPaymentAmount: 0,
                cumulateFullPaymentOrderIds: [],
                cumulateFullPaymentQuantity: 0,
                cumulateNotContractAmount: 0,
                cumulateNotContractOrderIds: [],
                cumulateNotContractQuantity: 0,
                cumulateNotFullPaymentAmount: 0,
                cumulateNotFullPaymentOrderIds: [],
                cumulateNotFullPaymentQuantity: 0,
                fullPaymentAmount: 0,
                fullPaymentOrderIds: [],
                fullPaymentQuantity: 0,
                notContractAmount: 0,
                notContractOrderIds: [],
                notContractQuantity: 0,
                retreatContractAmount: 0,
                retreatContractOrderIds: [],
                retreatContractQuantity: 0,
                retreatSubscribeAmount: 0,
                retreatSubscribeOrderIds: [],
                retreatSubscribeQuantity: 0,
                subscribeAmount: 0,
                subscribeNetWorthAmount: 0,
                subscribeNetWorthOrderIds: [],
                subscribeNetWorthQuantity: 0,
                subscribeOrderIds: [],
                subscribeQuantity: 0
              }
            })
        }
      },
      linkPageFun(item, isSum = false) {
        if (this.salesInfo[item.buildKey] === 0 && this.salesInfo[item.moneyKey] === 0) {
          return false
        }
        let params = {}
        if(this.$tool.getStorage('isbuildFlag') == 'nobuildpage'){
          // 工作台
          // 判断选择认购还是签约
          // 认购、退购、足未签、净认购、实际净认购、累计足未签 [1,2,6,8,9,11]
          // 签约、退签、净签约、已全款、累计为全款、回款

          console.log({
            ...this.checkParams,
            isSub:[1,2,6,8,9,11].indexOf(item.queryType)>=0?'subscribeAmount':'contractAmount',
            queryType:item.queryType
          },'subscribeSign')
          
          this.$router.push({
            name: 'subscribeSign',
            params: {
              ...this.checkParams,
              isSub:[1,2,6,8,9,11].indexOf(item.queryType)>=0?'subscribeAmount':'contractAmount',
              queryType:item.queryType
            }
          }) //认购签约订单
        }else{
          // containDate 1 认购 2退购,5签约 3 退签 6 全款
          switch (item.type) {
            case 'subscriptionOrder':
              params = {
                statusList: item.status,
                checkIndex: !isSum ? this.checkIndex : 5,
                checkTime: !isSum ? this.checkTime : ['', ''],
                containDate: item.containDate
              }
              dt.memory.set('subOrder_params', params)
              this.$router.push({
                name: 'subscriptionOrder',
                params: {
                  showCumulateNotFlag: item.buildKey ==
                    'notContractQuantity' ? true : false,
                  showNetWorthFlag: (item.buildKey ==
                    'subscribeQuantity' || item.buildKey == 'subscribeNetWorthQuantity' || item.buildKey=='actualSubscribeNetWorthQuantity') ? true : false ,// “认购”、“净认购”、“实际净认购”
                }
              }) //认购订单
              break
            case 'contractOrder':
              params = {
                statusList: item.status,
                checkIndex: !isSum ? this.checkIndex : 5,
                checkTime: !isSum ? this.checkTime : ['', ''],
                containDate: item.containDate
              }
              dt.memory.set('contractOrder_params', params)
              this.$router.push({
                name: 'contractOrder',
                params: {
                  showNetWorthFlag: (item.buildKey ==
                    'contractQuantity' || item.buildKey == 'contractNetWorthQuantity') ? true : false ,// “签约”、“净签约”
                }
              }) //签约订单
              break
            case 'paymentArrival':
              params = {
                creditStartTime: !isSum ? this.checkTime[0] : '',
                creditEndTime: !isSum ? this.checkTime[1] : '',
              }
              dt.memory.set('paymentArrival_params', params)

              this.$router.push({
                name: 'paymentArrival',
                params: {
                  receiptRecordStatus: item.status,
                  universalTime: this.checkTime
                }
              }) //回款到账
              break
            default:
              break
          }
        }
      },
    }
  }
</script>
<style lang="scss" scoped>
  .sales {
    margin-top: 1.2%;
    background-color: #fff;
    padding: 20px 15px;
    width: 100%;
    border-radius: 5px;
    color: #333;

    .title {
      padding-left: 8px;
      color: #222;
      font-size: 18px;
      border-left: 2px solid #2298ff;
      font-weight: bolder;
    }

    .sales-content {
      margin-top: 20px;
      font-size: 14px;
      width: 30%;

      li {
        width: 100%;
        line-height: 40px;
        border-bottom: 1px solid #dcdee2;

        .money {
          margin-left: 10px;
          color: #999;
        }
      }

      li:first-child {
        border-top: 1px solid #dcdee2;
      }
    }
  }
</style>